<?php

/**
 * SmartPHP framework
 *
 * @name SmartPHP framework
 * @package SmartPHP
 * @author 费尔 <admin@smartphp.cn>
 * @version 1.0 Beta
 * @link http://www.smartphp.cn
 * @copyright smartphp.cn
 * @license <a href="http://www.smartphp.cn">smartphp</a>
 */

namespace Base;

/**
 * Session 类
 * @author 费尔 <admin@xuai.cn>
 */
class Session {

    public static function init() {
        session_set_cookie_params(Config::get('session.lifetime') ?: NULL, Config::get('session.path') ?: NULL, Config::get('session.domain') ?: NULL, (boolean) Config::get('session.secure'), (boolean) Config::get('session.httponly'));
        session_name(Config::get('session.name') ?: 'FOXSESSID');
        if (Config::get('session.type')) {
            // 读取session驱动
            $class = false !== strpos(Config::get('session.type'), '\\') ? Config::get('session.type') : '\\Driver\\Session\\' . ucwords(Config::get('session.type'));
            // 检查驱动类
            if (!class_exists($class)) {
                trigger_error('error session handler:' . $class);
            }
            $handler = new $class(Config::get('session.options'));
            session_set_save_handler([&$handler, "open"], [&$handler, "close"], [&$handler, "read"], [&$handler, "write"], [&$handler, "destroy"], [&$handler, "gc"]);
        }
        session_start();
    }

}
